/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cxhd.pacs.controller.service;

import com.cxhd.pacs.model.FileDetail;
import com.cxhd.pacs.model.FileSystem;
import com.cxhd.pacs.tools.DateUtil;
import com.cxhd.pacs.tools.FileUtil;
import java.io.File;
import java.util.Date;

/**
 *
 * @author 52461
 */
public class HostService2 {

    public String saveHhtml(String study_iuid, String html) {

        String path = "";
        FileSystem bf = FileSystem.dao.getPathInfo();

        int fileSystemId = 0;
        String dir = "";
        String baseDir = "";
        String type = "html";
        if (bf != null) {
            baseDir = bf.get("base_path");
            dir = bf.get("base_path");
            fileSystemId = bf.getInt("pk");
        }

        File fs = new File(dir + "/" + DateUtil.getNumFolder());
        if (!fs.exists()) {
            fs.mkdirs();
        }
        String filePath = study_iuid + ".txt";
        String dateFolder = DateUtil.getNumFolder();
        fs = new File(dir + "/" + dateFolder + filePath);
          filePath = dateFolder + filePath;
        if (fs.exists()) {
            fs.delete();
        }
         String result = new FileDetail().saveInfo(type, fs.getName(), filePath, fs.length() + "", fileSystemId + "");
           
        FileUtil.writeText(fs.getAbsolutePath(), html);
        
        return result;

    }
}
